package web_router

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"mime"
	"net/http"
	"transport/framework/fw_config"
	"transport/framework/fw_socketio"
	"transport/framework/fw_ws"
	"transport/web/web_controller"
	"transport/web/web_thms_controller"
	"transport/web/web_view_controller"
)

var r = gin.Default()

func WebRouterInit() {
	// gin.SetMode(gin.ReleaseMode)
	// gin.DefaultWriter = ioutil.Discard
	crosConfig := cors.DefaultConfig()
	crosConfig.AllowAllOrigins = true
	// jeecgboot前端提交
	crosConfig.AddAllowHeaders("Authorization")
	r.Use(cors.New(crosConfig))
	// Set a lower memory limit for multipart forms (default is 32 MiB)
	r.MaxMultipartMemory = 8 << 20 // 8 MiB
	mime.AddExtensionType(".js", "application/javascript")
	r.StaticFS("/upload", http.Dir("./upload"))
	//r.Static("assets", "./dist/assets")
	//r.Use(static.Serve("/trans", static.LocalFile("./dist/", false)))
	web_controller.AuthRoute(r)
	web_controller.AuthDriverRoute(r)
	web_controller.UserRoute(r)
	web_controller.DictHeaderRoute(r)
	web_controller.DictItemRoute(r)
	web_controller.DriverRoute(r)
	web_controller.CarrierRoute(r)
	web_controller.CarRoute(r)
	web_controller.RouteRoute(r)
	web_controller.ImageRoute(r)
	web_controller.MerchantsRoute(r)
	web_controller.OrderRoute(r)
	web_controller.OrderDetailRoute(r)
	web_controller.TransBillRoute(r)
	web_controller.TrusteeRoute(r)
	web_controller.PrintTplRoute(r)
	//////////////////////////报表视图
	web_view_controller.OrderHeaderReportRoute(r)
	web_view_controller.OrderDetailReportRoute(r)
	fw_ws.WsInit(r)
	fw_socketio.SocketIoInit(r)
	////////////////////////////////////////thms gps
	web_thms_controller.ThmsRoute(r)
	web_thms_controller.GpsRoute(r)
	r.Run(":" + fw_config.GetConfigHandler().GetString("server.port"))
}
